import com.sun.jmx.snmp.SnmpString;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "test", value = "/test")
public class test extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String name="上山打老虎";
            request.setAttribute("name",name);
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三2");
        list.add("张三3");
        list.add("张三4");
        list.add("张三5");
        for (String n : list) {
            System.out.println(n);
        }


        request.setAttribute("names",list);// 将list集合放入到request里的names属性里(变量)
        // 请求转发
            request.getRequestDispatcher("/test.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
